import request from "@/uitls/request";
import { CategoryResponseData, Arrt } from "./type";
enum URL_API {
  //获取一级分类接口地址
  C1_URL = "/admin/product/getCategory1/",
  //获取二级分类接口地址
  C2_URL = "/admin/product/getCategory2/",
  //获取三级分类接口地址
  C3_URL = "/admin/product/getCategory3/",
  //获取分类下已有的属性与属性值
  ATTR_URL = "/admin/product/attrInfoList/",
  //添加或者修改已有的属性的接口
  ADDORUPDATEATTR_URL = "/admin/product/saveAttrInfo",
  //删除某一个已有的属性
  DELETEATTR_URL = "/admin/product/deleteAttr/",
}

export const getC1 = () =>
  request.get<any, CategoryResponseData>(URL_API.C1_URL);
export const getC2 = (category1Id: number | string) =>
  request.get<any, CategoryResponseData>(URL_API.C2_URL + category1Id);
export const getC3 = (category2Id: number | string) =>
  request.get<any, CategoryResponseData>(URL_API.C3_URL + category2Id);
export const reqAttr = (
  category1Id: string | number,
  category2Id: string | number,
  category3Id: string | number
) =>
  request.get<any, any>(
    URL_API.ATTR_URL + `${category1Id}/${category2Id}/${category3Id}`
  );
//新增或者修改已有的属性接口
export const reqAddOrUpdateAttr = (data: Arrt) =>
  request.post<any, any>(URL_API.ADDORUPDATEATTR_URL, data);
export const reqRemoveAttr = (attrId: number) =>
  request.delete<any, any>(URL_API.DELETEATTR_URL + attrId);
